package com.olap.starter.util.sql;

import org.springframework.stereotype.Service;

@Service
public class MysqlTaleSqlService implements TaleSqlService {

    private String tableSql = "SELECT table_name as value,CONCAT(table_name,'(',table_comment,')') AS label FROM information_schema.tables WHERE  table_schema = '%s'  order by table_name asc";
    private String columnSql = "SELECT table_name,column_name, \n" + "(CASE WHEN (is_nullable = 'no' && column_key != 'PRI') THEN 1 ELSE NULL END) AS is_required, \n" + "(CASE WHEN column_key = 'PRI' THEN 1 ELSE 0 END) AS is_pk, \n" + "(CASE WHEN column_key = 'PRI' THEN 0 ELSE 1 END) AS visible, \n" + "ordinal_position AS sort, column_comment, \n" + "(CASE WHEN extra = 'auto_increment' THEN 1 ELSE 0 END) AS is_increment, column_type\n" + ",1 AS checked FROM information_schema.columns WHERE table_schema = '%s' and table_name = '%s'\n" + "ORDER BY ordinal_position";

    @Override
    public String getTablesSql(String dbName) {
        return String.format(tableSql, dbName);
    }

    @Override
    public String getColumnsSql(String dbName, String tableName) {
        return String.format(columnSql, dbName, tableName);
    }
}
